function(kwin_add_effect_config name)
    list(REMOVE_ITEM ARGV ${name})
    kcoreaddons_add_plugin(${name} INSTALL_NAMESPACE "kwin/effects/configs" SOURCES ${ARGV})
    target_compile_definitions(${name} PRIVATE -DTRANSLATION_DOMAIN=\"kwin\")
endfunction()

# Add a CMake-time check for python3 to avoid failures during build.
find_package (Python3 COMPONENTS Interpreter)
add_feature_info("Python3" Python3_Interpreter_FOUND "Required to strip effects metadata")
set(KSEM_EXE "${CMAKE_CURRENT_SOURCE_DIR}/strip-effect-metadata.py")

function (kwin_strip_builtin_effect_metadata target metadata)
    set(stripped_metadata "${CMAKE_CURRENT_BINARY_DIR}/${metadata}.stripped")

    set(command ${KSEM_EXE} --source=${metadata} --output=${stripped_metadata})
    add_custom_command(
        OUTPUT ${stripped_metadata}
        COMMAND ${command}
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        DEPENDS ${metadata}
        COMMENT "Stripping ${metadata}..."
    )
    set_property(TARGET ${target} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS ${stripped_metadata})
endfunction()

macro(kwin_add_builtin_effect name)
    kcoreaddons_add_plugin(${name} STATIC SOURCES ${ARGN} INSTALL_NAMESPACE "kwin/effects/plugins")
    target_compile_definitions(${name} PRIVATE -DTRANSLATION_DOMAIN=\"kwin\")
    kwin_strip_builtin_effect_metadata(${name} metadata.json)
    install(FILES metadata.json DESTINATION ${KDE_INSTALL_DATADIR}/kwin/builtin-effects/ RENAME ${name}.json)
endmacro()

function(kwin_add_scripted_effect name source)
    kpackage_install_package(${source} ${name} effects kwin)

    # necessary so tests are found without installing
    file(COPY ${source}/contents ${source}/metadata.json DESTINATION ${CMAKE_BINARY_DIR}/bin/kwin/effects/${name})
endfunction()

function(kwin_add_script name source)
    kpackage_install_package(${source} ${name} scripts kwin)

    # Copy the script to the build directory so one can run tests without prior
    # make install. FIXME: use add_custom_command.
    file(COPY ${source}/contents ${source}/metadata.json DESTINATION ${CMAKE_BINARY_DIR}/bin/kwin/scripts/${name})
endfunction()

add_subdirectory(private)

add_subdirectory(backgroundcontrast)
add_subdirectory(blendchanges)
add_subdirectory(blur)
add_subdirectory(buttonrebinds)
add_subdirectory(colord-integration)
add_subdirectory(colorpicker)
add_subdirectory(desktopchangeosd)
add_subdirectory(desktopgrid)
add_subdirectory(dialogparent)
add_subdirectory(diminactive)
add_subdirectory(dimscreen)
add_subdirectory(eyeonscreen)
add_subdirectory(fade)
add_subdirectory(fadedesktop)
add_subdirectory(fadingpopups)
add_subdirectory(fallapart)
add_subdirectory(frozenapp)
add_subdirectory(fullscreen)
add_subdirectory(glide)
add_subdirectory(highlightwindow)
add_subdirectory(idletime)
add_subdirectory(invert)
add_subdirectory(kglobalaccel)
add_subdirectory(kpackage)
add_subdirectory(kscreen)
add_subdirectory(login)
add_subdirectory(logout)
add_subdirectory(magiclamp)
add_subdirectory(magnifier)
add_subdirectory(maximize)
add_subdirectory(minimizeall)
add_subdirectory(morphingpopups)
add_subdirectory(mouseclick)
add_subdirectory(mousemark)
add_subdirectory(nightcolor)
add_subdirectory(outputlocator)
add_subdirectory(overview)
add_subdirectory(qpa)
add_subdirectory(scale)
add_subdirectory(screenedge)
add_subdirectory(screenshot)
add_subdirectory(screentransform)
add_subdirectory(sessionquit)
add_subdirectory(sheet)
add_subdirectory(showfps)
add_subdirectory(showpaint)
add_subdirectory(slide)
add_subdirectory(slideback)
add_subdirectory(slidingpopups)
add_subdirectory(snaphelper)
add_subdirectory(squash)
add_subdirectory(startupfeedback)
add_subdirectory(stickykeys)
add_subdirectory(synchronizeskipswitcher)
add_subdirectory(thumbnailaside)
add_subdirectory(tileseditor)
add_subdirectory(touchpoints)
add_subdirectory(trackmouse)
add_subdirectory(translucency)
add_subdirectory(videowall)
add_subdirectory(windowaperture)
add_subdirectory(windowsystem)
add_subdirectory(windowview)
add_subdirectory(wobblywindows)
add_subdirectory(zoom)

if (KWIN_BUILD_DECORATIONS)
    add_subdirectory(kdecorations)
endif()
if (PipeWire_FOUND)
    add_subdirectory(screencast)
endif()
if (KWIN_BUILD_RUNNERS)
    add_subdirectory(krunner-integration)
endif()
